<!DOCTYPE html>
<html>
    <head>
        <title>Admin - Login</title>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
        <!-- Bootstrap -->
        <link href="../css/bootstrap.min.css" rel="stylesheet"/>
        <style>
            body { background-color: #f5f5f5;padding-top: 15px; font-size: 12px } 
            .main { max-width: 320px; margin: 0 auto; } 
            .login-or { position: relative; font-size: 18px; color: #aaa; margin-top: 5px; margin-bottom: 5px; padding-top: 5px; padding-bottom: 5px; } 
            .hr-or { background-color: #cdcdcd; height: 1px; margin-top: 0px !important; margin-bottom: 0px !important; } 
            h3 { text-align: center; line-height: 300%; }
        </style>
        <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
          <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <div class="container"> 
            <div class="row"> 
                <div class="main"> 
                    <h3>Log In</h3> 
                    <div class="login-or"> 
                        <hr class="hr-or"> 
                    </div> 
                    <form role="form" method="post"> 
                        <?php
                        require_once dirname(__FILE__) . "/../config/functions.php";
                        if (isset($_POST) && $_POST) {
                            $userName = $_POST['user_name'];
                            $userPassword = $_POST['user_password'];

                            $adminPassword = mysql_query("SELECT `value` FROM `option` where `key` = 'admin_password' ");
                            $adminUserName = mysql_query("SELECT `value` FROM `option` where `key` = 'admin_username' ");

                            $adminUserName = mysql_fetch_assoc($adminUserName);
                            $adminUserName = $adminUserName['value'];

                            $adminPassword = mysql_fetch_assoc($adminPassword);
                            $adminPassword = $adminPassword['value'];

                            if ($userName == $adminUserName && $userPassword == $adminPassword) {
                                $_SESSION['user'] = 'admin';
                                header("Location: index.php");
                            } else {
                                echo '<div class="alert alert-danger">Username or passwors wrong.</div>';
                            }
                        }
                        ?>
                        <div class="form-group"> 
                            <label for="inputUsernameEmail">Username</label> 
                            <input type="text" name="user_name" class="form-control" id="inputUsernameEmail"> 
                        </div> 
                        <div class="form-group"> 
                            <label for="inputPassword">Password</label> 
                            <input type="password" name="user_password" class="form-control" id="inputPassword">
                        </div>
                        <button type="submit" class="btn btn btn-primary"> Log In </button> 
                    </form>
                </div> 
            </div> 
        </div>
    </body>
</html>
